
const setting = {
    namespaced: true,
    state: {
        location: {},
        sys: {},
        tab_bar: {
            data: []
        },


    },
    mutations: {
        setLocation(state, data) {
            state.location = data;
        },
        setSys(state, data) {
            state.sys = data;
        },
        tabBar: function (state, data) {
            state.tab_bar = data;
        }
    },
    getters: {
        getLocation: function (state) {
            return state.location;
        },
        getPlatform: function (state) {
            return state.sys.platform;
        },
        getTabBar: function (state) {
            return state.tab_bar.data;
        },
        statusBarHeight: function (state) {
            return state.sys.statusBarHeight;
        },
        getNavBarHeight: function (state) {
            // #ifdef  H5
            return 44;
            // #endif
            // #ifndef H5
            return state.sys.platform === 'ios' ? 44 : 48;
            // #endif
        }
    },
    actions: {
        getLocation: function ({ commit }) {
            uni.getLocation({
                type: 'wgs84',
                success: function (res) {
                    commit('setLocation', res);
                }
            });
        },
        getSys: function ({ commit }) {
            uni.getSystemInfo({
                success: function (res) {
                    commit('setSys', res);
                }
            });
        },
        getTabBar: function ({ commit }) {
            return new Promise((resolve, reject) => {
                let $heshop = this._vm.$heshop;
                let $storageKey = this._vm.$storageKey;
                if (uni.getStorageSync($storageKey.tab_bar)) {
                    commit('tabBar', uni.getStorageSync($storageKey.tab_bar));
                    resolve();
                } else {
                    $heshop.fitment('post', {
                        keyword: 'tabbar'
                    }).then(function (res) {
                        let data = JSON.parse(res.content);
                        commit('tabBar', data);
                        uni.setStorageSync($storageKey.tab_bar, data);
                        resolve();
                    }).catch(function (err) {
                        console.error(err);
                        reject();
                    });
                }
            })
        }
    }
};

export default setting;
